﻿using DevExpress.ExpressApp.Blazor.Editors.Adapters;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Utils;
using Microsoft.AspNetCore.Components;

namespace EasyXaf.EntityDesigner.Editors.CodeEditors;

public class CodeEditorAdapter : ComponentAdapterBase
{
    public override CodeEditorModel ComponentModel { get; }

    public CodeEditorAdapter(CodeEditorModel model)
    {
        ComponentModel = model;
        ComponentModel.CodeChanged += (s, e) =>
        {
            ComponentModel.Code = e;
            RaiseValueChanged();
        };
    }

    protected override RenderFragment CreateComponent() => CodeEditorRenderer.Create(ComponentModel);

    public override object GetValue() => ComponentModel.Code;

    public override void SetValue(object value) => ComponentModel.Code = value as string;

    public override void SetAllowEdit(bool allowEdit) => ComponentModel.ReadOnly = !allowEdit;

    public override void SetAllowNull(bool allowNull) { }

    public override void SetDisplayFormat(string displayFormat) { }

    public override void SetEditMask(string editMask) { }

    public override void SetEditMaskType(EditMaskType editMaskType) { }

    public override void SetErrorIcon(ImageInfo errorIcon) { }

    public override void SetErrorMessage(string errorMessage) { }

    public override void SetIsPassword(bool isPassword) { }

    public override void SetMaxLength(int maxLength) { }

    public override void SetNullText(string nullText) { }
}
